﻿using System;
using System.Collections;
using System.Data;


public partial class Admin_News_QL_Yahoo : System.Web.UI.Page
{
    Data data = new Data();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["admin"].Equals("true") == false)
            {
                Response.Redirect("../Default.aspx");
            }
            else
            {
                LoadData();
            }
        }
        catch (Exception)
        {
            Response.Redirect("../Default.aspx");
            throw;
        }
    }

    private void LoadData()
    {
        if (Request.QueryString["edit"] != null && IsPostBack == false )
        {
            DataTable tableRow = data.GetTable_By_Where("Yahoo", "where YahooID=" + Request.QueryString["edit"]);
            txtYahooAddress.Text = tableRow.Rows[0]["YahooAddress"].ToString();
            txtYahooName.Text = tableRow.Rows[0]["YahooName"].ToString();
        }
        if (Request.QueryString["delete"] != null)
        {
            data.Delete_Yahoo(Request.QueryString["delete"]);
        }

        DataTable table = data.GetTable_By_Name("Yahoo");
        DataListYahoo.DataSource = table;
        DataListYahoo.DataBind();
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void btnSave_Click(object sender, EventArgs e)
    {
        if (Request.QueryString["edit"] != null)
        {
            data.Edit_Yahoo(Request.QueryString["edit"], txtYahooName.Text, txtYahooAddress.Text);
            Response.Redirect("Default.aspx");
        }
        if (Request.QueryString["edit"] == null && Request.QueryString["delete"] == null)
        {
            data.Add_Yahoo(txtYahooName.Text, txtYahooAddress.Text);
            Response.Redirect("Default.aspx");
        }
    }
}
